﻿module Tww.Pixxler.ColorTypes

[<Struct>]
type SimpleColor(r:int, g:int, b:int) = 
  member x.R = r
  member x.G = g
  member x.B = b
  // Create color with components in range 0-255
  member x.ClipColor() = 
    let check c = min 255 (max 0 c)
    SimpleColor(check r, check g, check b)
  // Component-wise addition of two colors
  static member (+) (c1:SimpleColor, c2:SimpleColor) = 
    SimpleColor(c1.R + c2.R, c1.G + c2.G, c1.B + c2.B)
  // Divide color components by an integer
  static member DivideByInt (c1:SimpleColor, n) = 
    SimpleColor(c1.R / n, c1.G / n, c1.B / n)
  // Multiply color components by an integer
  static member (*) (c1:SimpleColor, n) = 
    SimpleColor(c1.R * n, c1.G * n, c1.B * n)
  // Color initialized with zeros
  static member Zero = 
    SimpleColor(0, 0, 0)
